package org.jeecg.modules.zcgl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.modules.zcgl.entity.AssetFixed;
import org.jeecg.modules.zcgl.entity.AssetFixedMaintenance;
import org.jeecg.modules.zcgl.mapper.AssetFixedMaintenanceMapper;
import org.jeecg.modules.zcgl.service.IAssetFixedMaintenanceService;
import org.jeecg.modules.zcgl.service.IAssetFixedService;
import org.jeecg.modules.zcgl.vo.statistical.AssetMaintenanceVo;
import org.jeecg.modules.zcgl.vo.statistical.AssetScrapVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Description: 固定资产维修报废
 * @Author: jeecg-boot
 * @Date:   2021-07-02
 * @Version: V1.0
 */
@Service
public class AssetFixedMaintenanceServiceImpl extends ServiceImpl<AssetFixedMaintenanceMapper, AssetFixedMaintenance> implements IAssetFixedMaintenanceService {

    @Autowired
    private IAssetFixedService assetFixedService;

    @Override
    public IPage<AssetMaintenanceVo> queryAssetFixedMaintenancePageList(Page<AssetMaintenanceVo> page, QueryWrapper<AssetMaintenanceVo> queryWrapper) {
        return this.baseMapper.queryAssetFixedMaintenancePageList(page,queryWrapper);
    }

    @Override
    public IPage<AssetScrapVo> queryAssetFixedScrapPageList(Page<AssetScrapVo> page, QueryWrapper<AssetScrapVo> queryWrapper) {
        return this.baseMapper.queryAssetFixedScrapPageList(page,queryWrapper);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void maintenanceAsset(AssetFixedMaintenance assetFixedMaintenance) {
        AssetFixed assetFixed = assetFixedService.getById(assetFixedMaintenance.getAssetFixedId());
        if(assetFixed !=null){
            //状态 0-未生效 1-生效 2-借出 3-维修中 4-报废
            assetFixed.setStatus("3");
            assetFixedService.updateById(assetFixed);
            assetFixedMaintenance.setStatus(CommonConstant.STATUS_1);
            this.updateById(assetFixedMaintenance);
        }

    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void scrapAsset(AssetFixedMaintenance assetFixedMaintenance) {
        AssetFixed assetFixed = assetFixedService.getById(assetFixedMaintenance.getAssetFixedId());
        if(assetFixed !=null){
            //状态 0-未生效 1-生效 2-借出 3-维修中 4-报废
            assetFixed.setStatus("4");
            assetFixedService.updateById(assetFixed);
            assetFixedMaintenance.setStatus(CommonConstant.STATUS_1);
            this.updateById(assetFixedMaintenance);
        }
    }
}
